﻿Imports System
Imports System.Collections.Generic
Imports System.Configuration.Provider
Imports System.Web.Security

Namespace System.Workflow.Activities
    <Serializable> _
    Public Class WebWorkflowRole
        Inherits WorkflowRole
        ' Methods
        Public Sub New(ByVal roleName As String)
            If (roleName Is Nothing) Then
                Throw New ArgumentNullException("roleName")
            End If
            Me.m_roleName = roleName
            Me.m_roleProvider = Nothing
        End Sub

        Public Sub New(ByVal roleName As String, ByVal provider As String)
            If (roleName Is Nothing) Then
                Throw New ArgumentNullException("roleName")
            End If
            Me.m_roleName = roleName
            Me.m_roleProvider = provider
        End Sub

        Public Overrides Function GetIdentities() As IList([Of] String)
            Dim list As New List([Of] String)
            Dim roleProvider As RoleProvider = Me.GetRoleProvider
            list.AddRange(roleProvider.GetUsersInRole(Me.Name))
            Return list
        End Function

        Private Function GetRoleProvider() As RoleProvider
            If (Me.RoleProvider Is Nothing) Then
                Return Roles.Provider
            End If
            Dim provider As RoleProvider = Roles.Providers.Item(Me.RoleProvider)
            If (provider Is Nothing) Then
                Throw New ProviderException(SR.GetString("Error_RoleProviderNotAvailableOrEnabled", New Object() { Me.RoleProvider }))
            End If
            Return provider
        End Function

        Public Overrides Function IncludesIdentity(ByVal identity As String) As Boolean
            Return Me.GetRoleProvider.IsUserInRole(identity, Me.Name)
        End Function


        ' Properties
        Public Overrides Property Name As String
            Get
                Return Me.m_roleName
            End Get
            Set(ByVal value As String)
                If (value Is Nothing) Then
                    Throw New ArgumentNullException("value")
                End If
                Me.m_roleName = value
            End Set
        End Property

        Public Property RoleProvider As String
            Get
                Return Me.m_roleProvider
            End Get
            Set(ByVal value As String)
                Me.m_roleProvider = value
            End Set
        End Property


        ' Fields
        Private m_roleName As String
        Private m_roleProvider As String
    End Class
End Namespace

